<?php
namespace addon\cms\controller;

use app\common\controller\AddonAdminBase;
use tpfcore\Core;
use tpfcore\helpers\Json;
use think\Request;
// +----------------------------------------------------------------------
// | Author: yaoyihong <510974211@qq.com>
// +----------------------------------------------------------------------
/**
 * ============================================================================
 * 版权所有 2017-2077 tpframe工作室，并保留所有权利。
 * @link http://www.tpframe.com/
 * @copyright Copyright (c) 2017 TPFrame Software LLC
 * ----------------------------------------------------------------------------
 * 这不是一个自由软件！未经本公司授权您只能在不用于商业目的的前提下对程序代码进行修改和使用；
 * 不允许对程序代码以任何形式任何目的的再发布。
 * ============================================================================
 */
class PostsImages extends AddonAdminBase
{
    public function index()
    {
        $this->addonTemplate("index",[
            "list"=>Core::loadAddonModel("Posts")->getPostsList([
                "field"=>"__POSTS__.id,__POSTS__.title,__POSTS__.datetime,__POSTS__.cateid,__POSTS__.source,__POSTS__.author,__POSTS__.thumb,c.title ctitle",
                "paginate"=>["rows"=>20],
                "order"=>"datetime desc",
                "where"=>["channel_id"=>2],
                "join" =>['join' => "__CATEGORY__ c", 'condition' => "__POSTS__.cateid=c.id",'type' => 'left'],
            ])
        ]);
    }
    public function edit(){
        if(IS_POST){
            $this->jump(Core::loadAddonModel($this->name)->savePostsImages($this->param));
        }
        $list = Core::loadAddonModel("Posts")->getPostsList(["where"=>['id'=>$this->param['id']]]);
        $this->addonTemplate("edit",[
            'list'=>$list,
            'listPostsImages'=>Core::loadAddonModel($this->name)->getPostsImages(["where"=>['posts_id'=>$list[0]['id']]]),
            'categorys'=>Core::loadAddonModel("Category")->getTreeCategory(['parentid'=>$list[0]['cateid']])
        ]);
    }
    public function add()
    {
        if(IS_POST){
            $this->jump(Core::loadAddonModel($this->name)->savePostsImages($this->param));
        }
        $this->addonTemplate("add",[
            'categorys'=>Core::loadAddonModel("Category")->getTreeCategory($this->param)
        ]);
    }
    public function del()
    {
        $this->jump(Core::loadAddonModel($this->name)->delPostsImages($this->param));
    }
    public function del_imgae(){
         $this->jump(Core::loadAddonModel($this->name)->del_imgae($this->param));
    }
} 
